@extends('layouts.app')

@section('content')
<div class="content-header">
    <h1>修改部署配置</h1>
    <ol class="breadcrumb">
      <li><a href="{{ url('/') }}"><i class="fa fa-dashboard"></i> 首页</a></li>
      <li class="active">修改部署配置</li>
    </ol>
  </div>
<div class="content">
    @if (count($errors) > 0)
        <div class="alert alert-danger" role="alert">
            <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <ul>
            @foreach ($errors->all() as $error)
              <li>{{ $error }}</li>
            @endforeach
            </ul>
        </div>
    @endif
    <div class="row">
        <div class="col-md-12">
            <div class="panel panel-primary">
                <div class="panel-heading">
                    修改部署配置
                    <a class="pull-right label label-primary" href="{{ url('project/show/'.$repo_setting['repo_id']) }}">返回已配置列表</a>
                </div>

                <div class="panel-body">
                    <div class="alert alert-warning" role="alert">
                        <ol>
                            <li> SSH Config Host 字段需要进入部署服务器切换到 <label class="label label-primary">deploy</label> 用户查看 <label class="label label-primary">~/.ssh/config</label> </li>
                            <li> 新服务器请务必先执行 <a target="_blank" href="http://office243.digilinx.cn/jinchun/deploy/blob/master/init.sh">服务器初始化脚本</a></li>
                        </ol>
                    </div>
                    <form action="{{ url('project/update/'.$repo_setting['setting_id']) }}" method="post" class="form-horizontal">
                        <div class="form-group form-group-sm">
                            <label class="col-sm-3 control-label">Git Repo Url</label>
                            <div class="col-sm-8">
                                <input type="url" name="repo_url" class="form-control" value="{{ Input::old('repo_url', $repo_setting['repo_url']) }}" readonly>
                            </div>
                        </div>
                        <div class="form-group form-group-sm">
                            <label class="col-sm-3 control-label">配置名称 *</label>
                            <div class="col-sm-8">
                                <input type="text" name="name" class="form-control" value="{{ Input::old('name', $repo_setting['setting_name']) }}" placeholder="配置名称">
                                <span class="help-block control-label">部署时显示用</span>
                            </div>
                        </div>
                        <div class="form-group form-group-sm">
                            <label class="col-sm-3 control-label">SSH Config Host *</label>
                            <div class="col-sm-8">
                                <input type="text" name="ssh_host" class="form-control" value="{{ Input::old('ssh_host', $repo_setting['ssh_host']) }}" placeholder="{{ $repo_setting['ssh_host'] }}">
                                <span class="help-block control-label">部署服务器端 .ssh/config 里的 host 名称</span>
                            </div>
                            <!--<div class="col-sm-2">
                                <a href="" class=" btn btn-info btn-sm">测试连接</a>
                            </div>-->
                        </div>
                        <div class="form-group form-group-sm">
                            <label class="col-sm-3 control-label">服务器 App 应用路径 *</label>
                            <div class="col-sm-8">
                                <input type="text" name="app_path" class="form-control" value="{{ Input::old('app_path', $repo_setting['app_path']) }}" placeholder="{{ $repo_setting['app_path'] }}">
                                <span class="help-block control-label">请确保该路径 deploy 用户可读写</span>
                            </div>
                        </div>
                        <div class="form-group form-group-sm">
                            <label class="col-sm-3 control-label">服务器 Logs 路径</label>
                            <div class="col-sm-8">
                                <input type="text" name="app_logs_path" class="form-control" value="{{ Input::old('app_logs_path', $repo_setting['app_logs_path']) }}" placeholder="{{ $repo_setting['app_logs_path'] }}">
                                <span class="help-block control-label">请确保该路径 deploy 用户可读写</span>
                            </div>
                        </div>
                        <div class="form-group form-group-sm">
                            <label class="col-sm-3 control-label">服务器 Configs 路径</label>
                            <div class="col-sm-8">
                                <input type="text" name="app_configs_path" class="form-control" value="{{ Input::old('app_configs_path', $repo_setting['app_configs_path']) }}" placeholder="{{ $repo_setting['app_configs_path'] }}">
                                <span class="help-block control-label">请确保该路径 deploy 用户可读写</span>
                            </div>
                        </div>
                        <div class="form-group form-group-sm">
                            <label class="col-sm-3 control-label">服务器环境</label>
                            <div class="col-sm-4">
                                <select name="server_env" class="form-control">
                                    <option {{ Input::old('server_env') ? (Input::old('server_env') == 'Development' ? 'selected' : '' ) : ($repo_setting['server_env'] == 'Development' ? 'selected' : '') }} value="Development">Development</option>
                                    <option {{ Input::old('server_env') ? (Input::old('server_env') == 'Staging' ? 'selected' : '' ) : ($repo_setting['server_env'] == 'Staging' ? 'selected' : '') }} value="Staging">Staging</option>
                                    <option {{ Input::old('server_env') ? (Input::old('server_env') == 'Product' ? 'selected' : '' ) : ($repo_setting['server_env'] == 'Product' ? 'selected' : '') }} value="Product">Product</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group form-group-sm">
                            <label class="col-sm-3 control-label">默认部署分支</label>
                            <div class="col-sm-4">
                                <select name="default_branch" class="form-control">
                                    @foreach ($branches as $branch)
                                        <option {{ Input::old('default_branch') ? (Input::old('default_branch') == $branch['name'] ? 'selected' : '') : ($branch['name'] == $repo_setting['default_branch'] ? 'selected' : '') }} value="{{$branch['name']}}">{{ $branch['name'] }}</option>
                                    @endforeach
                                </select>
                            </div>
                        </div>
                        <div class="form-group form-group-sm">
                            <label class="col-sm-3 control-label">忽略文件（目录）列表</label>
                            <div class="col-sm-8">
                                <textarea class="form-control" name="exclude_files" placeholder="" rows="3">{{ Input::old('exclude_files')?:$repo_setting['exclude_files'] }}</textarea>
                                <span class="help-block control-label">每行表示一个文件（目录），请写文件（目录）名</span>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-offset-3 col-sm-10">
                                {!! csrf_field() !!}
                                <input type="hidden" name="repo_id" value="{{ $repo_setting['repo_id'] }}">
                                <button type="submit" class="btn btn-info">修改</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection


